package com.h2cloud.clone;

/**
 * @Package: com.h2cloud.clone
 * @ClassName: Person
 * @Author: h2cloud
 * @CreateTime: 2021/9/28 4:37 下午
 * @Description:
 */
public class Person {
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Object clone() {
        Object o = null;
        try {
            o = super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return o;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }


    public static void main(String[] args) {
        Person p1=new Person("zhangsan",18);
        Person p2=(Person)p1.clone();
        p2.setName("lis");
        p2.setAge(20);
        System.out.println("name="
                +p1.getName()+",age="+p1.getAge());
        //修改p2后，没有对p1产生影响。
    }
}
